package ntu.metaweb.http;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.concurrent.Executors;

import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;

@SuppressWarnings("restriction")
public class Server extends Thread {
	private HttpServer server;
	
	public Server(HttpHandler handler, int port) throws IOException {
		InetSocketAddress addr = new InetSocketAddress(port);
		this.server = HttpServer.create(addr, 0);
		this.server.createContext("/", handler);
		this.server.setExecutor(Executors.newCachedThreadPool());
		this.server.start();
		System.out.println("Server is listening on port " + port );
	}
}

